"""验证"""
from datetime import datetime

def validate_fields(data, fields):
    """验证字段不能为空"""
    for item in fields:
        if item not in data or data[item] is None:
            return None, f"字段 {item} 不能为空"
    return None, None


def validate_date_time(date_time):
    """验证时间格式是否正确"""
    try:
        timestamp = int(datetime.strptime(date_time, "%Y-%m-%d %H:%M:%S").timestamp())
        return timestamp, None
    except ValueError:
        return None, '请输入正确的时间格式, 例如: 2020-01-01 00:00:00'
